package ${pkg};

import java.io.PrintWriter;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.blue.jdbc.Page;
import com.blue.core.dict.annotation.DictParser;
import ${facadePkg}.${clazz}Facade;
import ${exceptionPkg}.${clazz}Exception;
import ${messagePkg}.${clazz}Request;
import ${messagePkg}.${clazz}Response;
import im.onclick.core.util.Const;
import im.onclick.core.util.JsonUtil;
<#if impList??>
<#list impList as vo>
import ${vo};
</#list>
</#if>

/**
 * ${name}控制器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 ${.now?string("yyyy年MM月dd日")}
 */
@Controller
@RequestMapping("/${module}")
public class ${clazz}Controller
{
	@Resource
	private ${clazz}Facade ${field}Facade;
	
	private static DictParser parser = DictParser.getInstance();
	
	public ${clazz}Controller()
	{
	}

	@GetMapping("/${view}_list" + Const.EXT)
	public String listGet(${clazz}Request request, Model model)
	{
		model.addAttribute("model", request);
		model.addAttribute("page", ${field}Facade.listPage(request, Const.PAGE_START, Const.PAGE_SIZE));
		model.addAttribute("map", parser.getStringMap());
		return "${module}/${view}_list";
	}
	
	@PostMapping("/${view}_list" + Const.EXT)
	public String listPost(${clazz}Request request, Page<${clazz}> page, Model model)
	{
		model.addAttribute("page", ${field}Facade.listPage(request, page.getCurPage(), page.getSize()));
		return "${module}/${view}_list_grid";
	}
	
	@GetMapping("/${view}_get" + Const.EXT)
	public String get(${clazz}Request request, Model model)
	{
		${clazz}Response response = null;
		if (request.getId() != null)
		{
			response = ${field}Facade.get(request);
		}
		model.addAttribute("model", response == null ? new ${clazz}Response() : response);
		model.addAttribute("map", parser.getStringMap());
		return "${module}/${view}_get";
	}
	
	@PostMapping("/${view}_save" + Const.EXT)
	public void save(${clazz}Request request, PrintWriter pw)
	{
		${clazz}Response response = null;
		if (request.getId() == null)
		{
			response = ${field}Facade.add(request);
		}
		else
		{
			response = ${field}Facade.update(request);
		}
		JsonUtil.outSuccess(pw, response);
	}
}
